var weatherInfo2 = function () {
	var prefManager = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefBranch);
	return {
		getWeather : function() {
			alert("cooasdl");
			weatherInfo2.getIP();
			alert("hot");
		},
		
		getIP : function() {
			alert("asd");
			xmlHttp=weatherInfo2.GetXmlHttpObject();

			if (xmlHttp==null) {
				alert ("Your browser does not support AJAX!");
				return;
			}
			url="http://weatherinfo.vaidikkapoor.info/getLocationDetails.php";
			alert("Loading 0");

			xmlHttp.onreadystatechange=function () {
				if (xmlHttp.readyState==1) {
					alert("Loading 1");
				}
				if (xmlHttp.readyState==2) {
					alert("Loading 2");
				}
				if (xmlHttp.readyState==3) {
					alert("Loading 3");
				}
				if (xmlHttp.readyState==4) {
					//document.getElementById("menuPlace").innerHTML=xmlHttp.responseText;
					var arg="";
					arg=xmlHttp.responseText;
					alert("got it");
					alert("call + " + arg);
					//window.openDialog('chrome://weather-info/content/weatherWindow.xul', 'nameofwindow', "chrome,centerscreen", arg);
					test(arg);
				}
			}

			xmlHttp.open("POST",url,true);
			xmlHttp.send(null);
		},
		GetXmlHttpObject : function() {
			var xmlHttp=null;
			try {
				// For Firefox, Opera 8.0+, Safari
				xmlHttp = new XMLHttpRequest();
			}
			catch (e) {
				// For Internet Explorer
				try {
					xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
				}
				catch (e) {
					xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
				}
			}
			return xmlHttp;
		}
	};
}();

function test(arg)
{
	//alert("asd");
	var inh = (new XMLSerializer()).serializeToString(document.getElementById("hello"));
	//alert(inh);
	var panel_var = document.getElementById("buttontest");
	//alert("out");
	alert("first check + " + arg);
	var parser = new DOMParser();
	var doc = parser.parseFromString(arg,"text/xml");
	var x = doc.documentElement;
	if (x.getElementsByTagName("ip")[0].getAttribute("value"))
		alert("google");
	alert("true + " + arg);
	//alert(x.getElementById("ip"));

	if (!panel_var.childNodes[0]) {	
	//alert("in");
		var IP = document.createElement("label");
                IP.setAttribute("value", "Weather Information for: ");
		IP.setAttribute("class", "panel_heading");
                panel_var.appendChild(IP);

		var loc = document.createElement("label");
                loc.setAttribute("value", x.getElementsByTagName("html:b")[0].innerHTML);
                loc.setAttribute("class", "location");
                panel_var.appendChild(loc);
//document.write(x.childNodes[0].childNodes[0].nodeValue);
		var IP = document.createElement("label");
		IP.setAttribute("value", "IP Address");
		panel_var.appendChild(IP);

		var temp_c = document.createElement("label");
	        temp_c.setAttribute("value", "Temperature (C): ");
	        panel_var.appendChild(temp_c);

		var temp_f = document.createElement("label");
                temp_f.setAttribute("value", "Temperature (F): ");
                panel_var.appendChild(temp_f);
		
		var wind_speed_k = document.createElement("label");
                wind_speed_k.setAttribute("value", "Wind Speed (KMPH): ");
                panel_var.appendChild(wind_speed_k);

		var wind_speed_m = document.createElement("label");
                wind_speed_m.setAttribute("value", "Wind Speed (Miles): ");
                panel_var.appendChild(wind_speed_m);

		var wind_dir = document.createElement("label");
                wind_dir.setAttribute("value", "Wind Direction (in degrees): ");
                panel_var.appendChild(wind_dir);

		var humidity = document.createElement("label");
                humidity.setAttribute("value", "Humidity: ");
                panel_var.appendChild(humidity);
		
		var cloud_cover = document.createElement("label");
                cloud_cover.setAttribute("value", "Cloud Cover: ");
                panel_var.appendChild(cloud_cover);

		var visibility = document.createElement("label");
                visibility.setAttribute("value", "Visibility: ");
                panel_var.appendChild(visibility);

		var image = document.createElement("label");
                image.setAttribute("value", "Image: ");
                panel_var.appendChild(image);
	}

}
alert("loaded");

